﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ProjetS5
{
    public class ScreenMessage
    {
        public ScreenMessage(String Message)
: this(Message, new TimeSpan(0, 0, 5))
        {
        }
        public ScreenMessage(String Message, TimeSpan ShowSpan)
        {
            beforeDisappearance = ShowSpan;
            message = Message;
        }

        public static SpriteFont messageFont;
        public TimeSpan beforeDisappearance;
        public TimeSpan fadeSpan = new TimeSpan(0, 0, 0, 0, 1500);
        public String message;
        public bool isFinished = false;

        public void Update(GameTime game)
        {
            if (beforeDisappearance.TotalMilliseconds > 0)
            {
                beforeDisappearance = beforeDisappearance.Subtract(game.ElapsedGameTime);
            }
            else if (fadeSpan.TotalMilliseconds > 0)
            {
                fadeSpan = fadeSpan.Subtract(game.ElapsedGameTime);
            }
            else
            {
                isFinished = true;
            }
        }

        public void Draw(GameTime game, SpriteBatch spriteBatch, int numero)
        {
            Vector2 dimension = messageFont.MeasureString(message);
            Vector2 position = new Vector2(500 - dimension.X / 2, 170 - 30 * numero);
            if (position.Y >= 0)
            {
                spriteBatch.DrawString(messageFont, message, position, Color.FromNonPremultiplied(250, 60, 60, (int)(fadeSpan.TotalMilliseconds / 1500f * 255f)));
            }
        }
    }
}
